package com.xinqing.test.algorithm.k8s.forecast;

import com.alibaba.fastjson.JSON;
import com.feidee.fdcommon.authorization.AuthorizationVerify;
import com.feidee.fdcommon.authorization.model.AuthInfoModel;
import com.feidee.fdcommon.configuration.CustomConfiguration;
import com.feidee.fdcommon.model.StringResponse;
import com.feidee.fdcommon.util.HttpUtil;
import com.xinqing.test.modle.algorithm.ForecastParam;
import org.apache.http.Consts;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Author:CHQ
 * @Date:2020/9/29 17:03
 * @Description
 */
public class STfae005ec38154f24 {
    public static void main(String args[]) throws Exception {
        Date d = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String time = sdf.format(d);


    /*   String data="{\"busId\":\"ad_ctr\"," +
                "\"features\":{\"n1\":\"1\",\"n2\":\"5\",\"n3\":\"11\",\"n4\":\"0\",\"n5\":\"0\",\"n6\":\"2\",\"n7\":\"9\",\"n8\":\"11\"," +
                "\"n9\":\"0\",\"u31\":\"1\",\"us1\":\"1\",\"us0\":\"68\",\"us3\":\"6000\",\"t1\":\"2020-09-29 17:23:27\"}," +
                "\"models\":[\"693ba772fab3a1d8\",\"951c327c56779183\"]," +
                "\"multiFeatures\":{\"97516\":{\"u32\":\"1\",\"us2\":\"0.0147\",\"us4\":\"57\",\"u37\":\"0\",\"u36\":\"0\",\"u39\":\"1\",\"u17\":\"0\",\"u38\":\"249\"}," +
                "\"top\":\"0\","+
                "\"traceId\":\"990a790a29f9e8e1d6335693ebd8a70639ba691ef4735c761554171a6fed822afcfe3475eb3dce68f890e69d73268796\"}";*/

    String datas="{\n" +
            "\t\"sex\": \"0\",\n" +
            "\t\"e_b\": \"0\",\n" +
            "\t\"e_c\": \"0\",\n" +
            "\t\"e_d\": \"0\",\n" +
            "\t\"e_e\": \"0\",\n" +
            "\t\"e_f\": \"0\",\n" +
            "\t\"e_g\": \"0\",\n" +
            "\t\"e_h\": \"0\",\n" +
            "\t\"e_i\": \"0\",\n" +
            "\t\"s_a\": \"0\",\n" +
            "\t\"s_b\": \"0\",\n" +
            "\t\"s_c\": \"0\",\n" +
            "\t\"s_d\": \"0\",\n" +
            "\t\"s_e\": \"0\",\n" +
            "\t\"a_g_c_qth\": \"0\",\n" +
            "\t\"a_g_c_sm\": \"0\",\n" +
            "\t\"a_g_c_dys\": \"0\",\n" +
            "\t\"a_g_c_zs\": \"0\",\n" +
            "\t\"a_g_c_fs\": \"0\",\n" +
            "\t\"a_g_c_bd\": \"0\",\n" +
            "\t\"a_g_c_bj\": \"0\",\n" +
            "\t\"a_g_c_pn\": \"0\",\n" +
            "\t\"a_g_c_np\": \"0\",\n" +
            "\t\"a_g_c_nc\": \"0\",\n" +
            "\t\"a_g_c_nt\": \"0\",\n" +
            "\t\"a_g_c_xm\": \"0\",\n" +
            "\t\"a_g_c_tzs\": \"0\",\n" +
            "\t\"a_g_c_jl\": \"0\",\n" +
            "\t\"a_g_c_wzs\": \"0\",\n" +
            "\t\"a_g_c_hlbe\": \"0\",\n" +
            "\t\"a_g_c_xn\": \"0\",\n" +
            "\t\"a_g_c_jx\": \"0\",\n" +
            "\t\"a_g_c_dlbz\": \"0\",\n" +
            "\t\"a_g_c_dl\": \"0\",\n" +
            "\t\"a_g_c_ty\": \"0\",\n" +
            "\t\"a_g_c_nb\": \"0\",\n" +
            "\t\"a_g_c_yc\": \"0\",\n" +
            "\t\"a_g_c_yy\": \"0\",\n" +
            "\t\"a_g_c_cz\": \"0\",\n" +
            "\t\"a_g_c_lf\": \"0\",\n" +
            "\t\"a_g_c_dy\": \"0\",\n" +
            "\t\"a_g_c_yz\": \"0\",\n" +
            "\t\"a_g_c_jys\": \"0\",\n" +
            "\t\"a_g_c_wx\": \"0\",\n" +
            "\t\"a_g_c_hz\": \"0\",\n" +
            "\t\"a_g_c_lz\": \"0\",\n" +
            "\t\"a_g_c_wh\": \"0\",\n" +
            "\t\"a_g_c_sy\": \"0\",\n" +
            "\t\"a_g_c_qz\": \"0\",\n" +
            "\t\"a_g_c_ta\": \"0\",\n" +
            "\t\"a_g_c_tz\": \"0\",\n" +
            "\t\"a_g_c_ly\": \"0\",\n" +
            "\t\"a_g_c_jn\": \"0\",\n" +
            "\t\"a_g_c_jy\": \"0\",\n" +
            "\t\"a_g_c_hk\": \"0\",\n" +
            "\t\"a_g_c_zb\": \"0\",\n" +
            "\t\"a_g_c_hbss\": \"0\",\n" +
            "\t\"a_g_c_wn\": \"0\",\n" +
            "\t\"a_g_c_hzs\": \"0\",\n" +
            "\t\"a_g_c_xts\": \"0\",\n" +
            "\t\"a_g_c_xxtj\": \"0\",\n" +
            "\t\"a_g_c_zjss\": \"0\",\n" +
            "\t\"a_g_c_xzs\": \"0\",\n" +
            "\t\"a_g_c_bzs\": \"0\",\n" +
            "\t\"a_g_c_zzss\": \"0\",\n" +
            "\t\"a_g_c_wfs\": \"0\",\n" +
            "\t\"a_g_c_czss\": \"0\",\n" +
            "\t\"a_g_c_pys\": \"0\",\n" +
            "\t\"a_g_c_ytss\": \"0\",\n" +
            "\t\"a_g_c_mdj\": \"0\",\n" +
            "\t\"a_g_c_zhs\": \"0\",\n" +
            "\t\"a_g_c_mms\": \"0\",\n" +
            "\t\"a_g_c_hyss\": \"0\",\n" +
            "\t\"a_g_c_zyss\": \"0\",\n" +
            "\t\"a_g_c_gzs\": \"0\",\n" +
            "\t\"a_g_c_dqzz\": \"0\",\n" +
            "\t\"a_g_c_sns\": \"0\",\n" +
            "\t\"a_g_c_zys\": \"0\",\n" +
            "\t\"a_g_c_sys\": \"0\",\n" +
            "\t\"a_g_c_zzs\": \"0\",\n" +
            "\t\"a_g_c_eeds\": \"0\",\n" +
            "\t\"a_g_c_jqs\": \"0\",\n" +
            "\t\"a_g_c_jhs\": \"0\",\n" +
            "\t\"a_g_c_jb\": \"0\",\n" +
            "\t\"a_g_c_qzs\": \"0\",\n" +
            "\t\"a_g_c_tls\": \"0\",\n" +
            "\t\"a_g_c_trs\": \"0\",\n" +
            "\t\"a_g_c_ycs\": \"0\",\n" +
            "\t\"a_g_c_xls\": \"0\",\n" +
            "\t\"a_g_c_jxss\": \"0\",\n" +
            "\t\"a_g_c_zjs\": \"0\",\n" +
            "\t\"a_g_c_ccs\": \"0\",\n" +
            "\t\"a_g_c_cc\": \"0\",\n" +
            "\t\"a_g_c_czs\": \"0\",\n" +
            "\t\"a_g_c_hxx\": \"0\",\n" +
            "\t\"a_g_c_hys\": \"0\",\n" +
            "\t\"a_g_c_fcg\": \"0\",\n" +
            "\t\"a_g_c_yjs\": \"0\",\n" +
            "\t\"a_g_c_yqs\": \"0\",\n" +
            "\t\"a_g_c_abzz\": \"0\",\n" +
            "\t\"a_g_c_alsm\": \"0\",\n" +
            "\t\"a_g_c_lns\": \"0\",\n" +
            "\t\"a_g_c_szss\": \"0\",\n" +
            "\t\"a_g_c_yas\": \"0\",\n" +
            "\t\"a_g_c_qds\": \"0\",\n" +
            "\t\"a_g_c_ass\": \"0\",\n" +
            "\t\"a_g_c_sgs\": \"0\",\n" +
            "\t\"a_g_c_mass\": \"0\",\n" +
            "\t\"a_g_c_zmds\": \"0\",\n" +
            "\t\"a_g_c_jxs\": \"0\",\n" +
            "\t\"a_g_c_hbsss\": \"0\",\n" +
            "\t\"a_g_c_hgss\": \"0\",\n" +
            "\t\"a_g_c_yts\": \"0\",\n" +
            "\t\"a_g_c_hgs\": \"0\",\n" +
            "\t\"a_g_c_hss\": \"0\",\n" +
            "\t\"a_g_c_hsss\": \"0\",\n" +
            "\t\"a_g_c_hhs\": \"0\",\n" +
            "\t\"a_g_c_qdnmz\": \"0\",\n" +
            "\t\"a_g_c_qdnyz\": \"0\",\n" +
            "\t\"a_g_c_qxnby\": \"0\",\n" +
            "\t\"a_g_c_qqhe\": \"0\",\n" +
            "\t\"a_g_c_lys\": \"0\",\n" +
            "\t\"a_g_c_sh\": \"0\",\n" +
            "\t\"a_g_c_dg\": \"0\",\n" +
            "\t\"a_g_c_nj\": \"0\",\n" +
            "\t\"a_g_c_hf\": \"0\",\n" +
            "\t\"a_g_c_tj\": \"0\",\n" +
            "\t\"a_g_c_gz\": \"0\",\n" +
            "\t\"a_g_c_cd\": \"0\",\n" +
            "\t\"a_g_c_km\": \"0\",\n" +
            "\t\"a_g_c_sz\": \"0\",\n" +
            "\t\"a_g_c_wz\": \"0\",\n" +
            "\t\"a_g_c_fz\": \"0\",\n" +
            "\t\"a_g_c_szs\": \"0\",\n" +
            "\t\"a_g_c_xa\": \"0\",\n" +
            "\t\"a_g_c_gy\": \"0\",\n" +
            "\t\"a_g_c_zz\": \"0\",\n" +
            "\t\"a_g_c_cq\": \"0\",\n" +
            "\t\"a_g_p_nmg\": \"0\",\n" +
            "\t\"a_g_p_bjs\": \"0\",\n" +
            "\t\"a_g_p_jlp\": \"0\",\n" +
            "\t\"a_g_p_ajly\": \"0\",\n" +
            "\t\"a_g_p_nxhz\": \"0\",\n" +
            "\t\"a_g_p_sxp\": \"0\",\n" +
            "\t\"a_g_p_lnp\": \"0\",\n" +
            "\t\"a_g_p_sh\": \"0\",\n" +
            "\t\"a_g_p_yn\": \"0\",\n" +
            "\t\"a_g_p_sc\": \"0\",\n" +
            "\t\"a_g_p_tj\": \"0\",\n" +
            "\t\"a_g_p_ah\": \"0\",\n" +
            "\t\"a_g_p_sd\": \"0\",\n" +
            "\t\"a_g_p_gd\": \"0\",\n" +
            "\t\"a_g_p_gx\": \"0\",\n" +
            "\t\"a_g_p_js\": \"0\",\n" +
            "\t\"a_g_p_jx\": \"0\",\n" +
            "\t\"a_g_p_hb\": \"0\",\n" +
            "\t\"a_g_p_hn\": \"0\",\n" +
            "\t\"a_g_p_zj\": \"0\",\n" +
            "\t\"a_g_p_hbs\": \"0\",\n" +
            "\t\"a_g_p_hns\": \"0\",\n" +
            "\t\"a_g_p_fj\": \"0\",\n" +
            "\t\"a_g_p_gz\": \"0\",\n" +
            "\t\"a_g_p_cq\": \"0\",\n" +
            "\t\"a_g_p_sx\": \"0\",\n" +
            "\t\"a_g_p_hlj\": \"0\",\n" +
            "\t\"app_m_h_n_m1\": \"-1\",\n" +
            "\t\"app_m_h_n_m3\": \"-1\",\n" +
            "\t\"app_m_h_n_m6\": \"-1\",\n" +
            "\t\"app_m_h_n_m12\": \"-1\",\n" +
            "\t\"app_u_n_m1\": \"-1\",\n" +
            "\t\"app_u_n_m3\": \"-1\",\n" +
            "\t\"app_u_n_m6\": \"-1\",\n" +
            "\t\"app_u_n_m12\": \"-1\",\n" +
            "\t\"bj_hys\": \"-1\",\n" +
            "\t\"tx_s1\": \"-1\",\n" +
            "\t\"tx_s2\": \"-1\",\n" +
            "\t\"tx_s3\": \"-1\",\n" +
            "\t\"tx_s4\": \"-1\",\n" +
            "\t\"tx_s5\": \"-1\",\n" +
            "\t\"tx_s6\": \"-1\",\n" +
            "\t\"zh_l_c\": \"-1\",\n" +
            "\t\"zh_o_c\": \"-1\",\n" +
            "\t\"zh_l_b\": \"-1\",\n" +
            "\t\"zh_3m_p_q\": \"-1\",\n" +
            "\t\"zh_6_p_q\": \"-1\",\n" +
            "\t\"zh_12m_p_q\": \"-1\",\n" +
            "\t\"zh_1m_l_q\": \"-1\",\n" +
            "\t\"zh_3m_l_q\": \"-1\",\n" +
            "\t\"zh_6m_l_q\": \"-1\",\n" +
            "\t\"zh_12m_l_q\": \"-1\",\n" +
            "\t\"zh_3m_q\": \"-1\",\n" +
            "\t\"zh_6m_q\": \"-1\",\n" +
            "\t\"zh_12m_q\": \"-1\",\n" +
            "\t\"zh_q_a\": \"-1\",\n" +
            "\t\"zh_t_o\": \"-1\",\n" +
            "\t\"bh_c_l_s\": \"-1\",\n" +
            "\t\"bh_l_c\": \"-1\",\n" +
            "\t\"bh_r_a\": \"-1\",\n" +
            "\t\"bh_r_a_c\": \"-1\",\n" +
            "\t\"bh_o_l_c\": \"-1\",\n" +
            "\t\"bh_m_l_p\": \"-1\",\n" +
            "\t\"bh_c_l_s_180c\": \"-1\",\n" +
            "\t\"bh_c_l_s_360c\": \"-1\",\n" +
            "\t\"bh_l_c_360\": \"-1\",\n" +
            "\t\"bh_l_a_30\": \"-1\",\n" +
            "\t\"bh_l_a_90\": \"-1\",\n" +
            "\t\"bh_l_a_180\": \"-1\",\n" +
            "\t\"bh_l_a_360\": \"-1\",\n" +
            "\t\"bh_l_a_90c\": \"-1\",\n" +
            "\t\"bh_l_a_180c\": \"-1\",\n" +
            "\t\"bh_l_a_360c\": \"-1\",\n" +
            "\t\"bh_1q_n_1m\": \"-1\",\n" +
            "\t\"bh_1q_n_3m\": \"-1\",\n" +
            "\t\"bh_1q_n_6m\": \"-1\",\n" +
            "\t\"bh_1q_n_12m\": \"-1\",\n" +
            "\t\"bh_m_l_a_30\": \"-1\",\n" +
            "\t\"bh_m_l_a_90\": \"-1\",\n" +
            "\t\"bh_m_l_a_180\": \"-1\",\n" +
            "\t\"bh_m_l_a_360\": \"-1\",\n" +
            "\t\"bh_a_30\": \"-1\",\n" +
            "\t\"bh_a_90\": \"-1\",\n" +
            "\t\"bh_a_180\": \"-1\",\n" +
            "\t\"bh_a_360\": \"-1\",\n" +
            "\t\"bh_a_c_180c\": \"-1\",\n" +
            "\t\"ssj_u\": \"0\",\n" +
            "\t\"score\": \"-1\",\n" +
            "\t\"self_r_t\": \"-1\",\n" +
            "\t\"pt_r_t\": \"-1\",\n" +
            "\t\"b_r_t\": \"-1\",\n" +
            "\t\"m_p\": \"-1\",\n" +
            "\t\"is_s_c_c\": \"-1\",\n" +
            "\t\"r3m_l_c\": \"-1\",\n" +
            "\t\"gh_s\": \"-1\",\n" +
            "\t\"gh_s_c\": \"-1\",\n" +
            "\t\"gh_c_s_c\": \"-1\",\n" +
            "\t\"gh_c_f_s_c\": \"-1\",\n" +
            "\t\"gh_c_s_s_c\": \"-1\",\n" +
            "\t\"gh_c_s_c_r\": \"-1\",\n" +
            "\t\"gh_c_s_s_c_r\": \"-1\",\n" +
            "\t\"gh_c_f_s_c_r\": \"-1\",\n" +
            "\t\"gh_p_s_c\": \"-1\",\n" +
            "\t\"gh_p_s_s_c\": \"-1\",\n" +
            "\t\"gh_p_f_s_c\": \"-1\",\n" +
            "\t\"gh_p_s_c_r\": \"-1\",\n" +
            "\t\"gh_p_f_s_c_r\": \"-1\",\n" +
            "\t\"gh_p_s_s_c_r\": \"-1\",\n" +
            "\t\"gh_d10_c\": \"-1\",\n" +
            "\t\"gh_d30_c\": \"-1\",\n" +
            "\t\"gh_h_d10_c\": \"-1\",\n" +
            "\t\"gh_h_d_c\": \"-1\"\n" +
            "}";
        ForecastParam forecastParam = new ForecastParam();
        forecastParam.setBusId("ad_wdl");
        Map<String, Object> featuresMap  = (Map<String, Object>) JSON.parse(datas);
        forecastParam.setFeatures(featuresMap);
       // "\"multiFeatures\":{\"97516\":{\"u32\":\"1\",\"us2\":\"0.0147\",\"us4\":\"57\",\"u37\":\"0\",\"u36\":\"0\",\"u39\":\"1\",
        // \"u17\":\"0\",\"u38\":\"249\"}," +
        HashMap<String, Map<String, Object>> multiFeaturesMap = new HashMap<>();
        HashMap<String, Object> map = new HashMap<>();
    /*    map.put("c3","98");
        map.put("c4","0");
        map.put("c7","SSJSYYYW");
        map.put("c0","42539");*/
       // multiFeaturesMap.put("96544",map);
      //  forecastParam.setMultiFeatures(multiFeaturesMap);
        //"\"models\":[\"693ba772fab3a1d8\",\"951c327c56779183\"]," +
    //    forecastParam.setModels(new String[]{"aa1435d0024cacf1","1d17ee93a0132f02"});
        forecastParam.setModels(new String[]{"387a454cce082929"});
        forecastParam.setTop(0);

        String data = JSON.toJSONString(forecastParam);

        //分配的AccessKeyId
        String accessKeyId = "data_team";
        //分配的AccessSecret
        String accessSecret = "MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAJ6+UYiQtt2OYfyfBF8e12kjd6nnF0Zl1s23f7l+eSl07xQxoxACSXyO3aq/tF7g0IiQZev4SF7ZA/oAOIYlYo0CAwEAAQ==";

       // String url = "http://10.201.7.239:8063/sml/forecast/realTimes";
        String url = "https://tg.feidee.net/model/fae005ec38154f24";
       // String url = "https://sml.suishoudata.com/model/fae005ec38154f24";

        //调用鉴权工具包计算鉴权信息,data不存则传空
        AuthInfoModel authInfo = AuthorizationVerify.getAuthInfo(url, data, accessKeyId, accessSecret);
        //获取GMT时间+
        String date = authInfo.getDate();
        //获取加密之后的data，若传入data为空，则密文也为空
        String ciphertext = authInfo.getCiphertext();
        //获取认证信息
        String authorization = authInfo.getAuthorization();

        //构造请求
        HttpPost method = null;
        try {
            method = new HttpPost(url);
            method.setHeader("Date", date);
            method.setHeader("Authorization", authorization);
            method.setHeader("AuthVersion", "2");
            if (ciphertext != null) {
                //加密之后data通过http body传输
                StringEntity stringEntity = new StringEntity(ciphertext, Consts.UTF_8);
                stringEntity.setContentEncoding("UTF-8");
                stringEntity.setContentType("application/json");
                method.setEntity(stringEntity);
            }
            CustomConfiguration.setString("http.connection.socket.timeout", "50000");
            StringResponse response = HttpUtil.post(method);
            System.out.println("rslt:" + response.getResponseBody());
        } finally {
            if (method != null) {
                method.releaseConnection();
            }
        }


    }
}
